<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Input;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    // 对应的模型
    protected $model;
    protected $controller;

    public function __construct()
    {
        $route = Route::currentRouteAction();
        list($controller, $action) = explode('@', $route);

        $controller = str_replace("App\Http\Controllers\\", "", $controller);
        $this->controller = strtolower(str_replace("Controller", "", $controller));
        $this->model = 'App\Models\\' . ucfirst($this->controller);
    }

    //图片上传
    public function upload()
    {
        $file = Input::file('Filedata');
        $url = Input::get("file_path");
        $url = $url ? $url : "";
        if ($file->isValid()) {
            $entension = $file->getClientOriginalExtension(); //上传文件的后缀.
            $newName = date('YmdHis') . mt_rand(10000, 99999) . '.' . $entension;
            $path = $file->move(base_path() . '/public/uploads/temp', $newName);
            $filepath = '/uploads/temp/' . $newName;
            return $filepath;
        }
    }

}
